#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Node {
    char data;
    Node* left;
    Node* right;
    Node(char data) : data(data), left(nullptr), right(nullptr) {}
};


Node* buildTree(vector<string>& nodes) {
    std::vector<Node*> nodePool;
    int count = 0;
    for (const auto& nodeInfo : nodes) {
        char data = nodeInfo[0];
        Node* newNode;
        if (count==0){newNode = new Node(data);count++;nodePool.push_back(newNode);}
        else {
            for (int i=1;i<nodePool.size();i++) {if (nodePool[i]->data==data){newNode =nodePool[i];}}
        }


        if (nodeInfo[1] == '*')newNode->left = nullptr; 
        else {
            Node *left=new Node(nodeInfo[1]);
            newNode->left = left;
            nodePool.push_back(left);
            
        }
        if (nodeInfo[2] == '*')newNode->right = nullptr; 
        else {
            Node *right=new Node(nodeInfo[2]);
            newNode->right = right;
            nodePool.push_back(right);
        }

        
    }
    return nodePool.front(); 
}

bool areMirror(Node* left, Node* right) {
    
    if (left == nullptr && right == nullptr) {
        return true;
    }
    
    if (left == nullptr || right == nullptr) {
        return false;
    }
   
    return areMirror(left->left, right->right) && areMirror(left->right, right->left);
}


bool isSymmetric(Node* root) {
  
    if (root == nullptr) {
        return true;
    }

    return areMirror(root->left, root->right);
}

int main() {
    int n;
    std::cin >> n;
    std::vector<std::string> nodes(n);
    for (int i = 0; i < n; ++i) {
        cin>>nodes[i];
    }

    Node* root = buildTree(nodes);
    bool judge = isSymmetric(root);
    if (judge) {cout<<"true";}
    else {cout<<"false";}
    return 0;
}